"""
Copyright (c) 2022 Guangdong University of Technology
PhotLab is licensed under [Open Source License].
You can use this software according to the terms and conditions of the [Open Source License].
You may obtain a copy of [Open Source License] at: [https://open.source.license/]

THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.

See the [Open Source License] for more details.

Author: Meng Xiang, Xiaoxue Gan
Created: 2023/8/19
Supported by: National Key Research and Development Program of China
"""


import numpy as np
import math


def mzm(opt_carrier, elec_signal, bias, Vpi = 6, Extinction_ratio = 30):
    """

    Args:
        pt_carrier: 光载波
        elec_signal: 电信号
        bias：偏置电压
        Vpi：半波电压
        Extinction_ratio：消光比

    Returns:
        mzm_output：调制后光信号

    """

    alpha = np.sqrt(1 / 10 ** (Extinction_ratio / 10))
    signal_i = elec_signal

    mzm_Out = np.sqrt(0.5 + alpha) * np.exp(1j * (signal_i / Vpi * math.pi + bias / Vpi * math.pi)) + np.sqrt(0.5 - alpha) * np.exp(-1j * (signal_i / Vpi * math.pi + bias / Vpi * math.pi))

    mzm_output = mzm_Out * opt_carrier
    return mzm_output
